package com.hemaapp.thyc.model;

import com.hemaapp.hm_FrameWork.HemaUser;
import com.hemaapp.hm_FrameWork.exception.DataParseException;
import com.hemaapp.hm_FrameWork.model.Image;
import com.hemaapp.hm_FrameWork.orm.annotation.TableName;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 用户信息(注意User信息必须继承HemaUser,并且User中不用再包含token字段)
 */
@TableName(table = "user")
public class User extends HemaUser implements Serializable {

    private static final long serialVersionUID = -8412756093515557415L;

    private String id;
    private String usertype;
    private String serviceflag;
    private String username;
    private String email;
    private String password;
    private String paypassword;
    private String cashpassword;
    private String nickname;
    private String charindex;
    private String mobile;
    private String avatar;
    private String tel;
    private String avatarbig;
    private String district_name;
    private String onlineflag;
    private String validflag;
    private String vestflag;
    private String score;
    private String feeaccount;
    private String lng;
    private String lat;
    private String deviceid;
    private String devicetype;
    private String channelid;
    private String lastloginversion;
    private String lastlogintime;
    private String login;
    private String regip;
    private String regdate;
    private String content;
    private String thirdtype;
    private String thirduid;
    private String bankname;
    private String bankaddress;
    private String bankcard;
    private String c_bankname;
    private String c_bankaddress;
    private String c_bankcard;
    private String android_must_update;
    private String android_last_version;
    private String android_update_url;
    private String servicerange;
    private String workyears;
    private ArrayList<Image> imgItems1 = new ArrayList<>();
    private ArrayList<Image> imgItems2 = new ArrayList<>();
    private ArrayList<Image> imgItems3 = new ArrayList<>();


    public User(JSONObject jsonObject) throws DataParseException {
        super(jsonObject);
        if (jsonObject != null) {
            try {
                id = get(jsonObject, "id");
                usertype = get(jsonObject, "usertype");
                serviceflag = get(jsonObject, "serviceflag");
                username = get(jsonObject, "username");
                email = get(jsonObject, "email");
                password = get(jsonObject, "password");
                paypassword = get(jsonObject, "paypassword");
                cashpassword = get(jsonObject, "cashpassword");
                nickname = get(jsonObject, "nickname");
                charindex = get(jsonObject, "charindex");
                mobile = get(jsonObject, "mobile");
                tel = get(jsonObject, "tel");
                avatar = get(jsonObject, "avatar");
                avatarbig = get(jsonObject, "avatarbig");
                district_name = get(jsonObject, "district_name");
                onlineflag = get(jsonObject, "onlineflag");
                validflag = get(jsonObject, "validflag");
                vestflag = get(jsonObject, "vestflag");
                score = get(jsonObject, "score");
                feeaccount = get(jsonObject, "feeaccount");
                lng = get(jsonObject, "lng");
                lat = get(jsonObject, "lat");
                deviceid = get(jsonObject, "deviceid");
                devicetype = get(jsonObject, "devicetype");
                channelid = get(jsonObject, "channelid");
                lastloginversion = get(jsonObject, "lastloginversion");
                lastlogintime = get(jsonObject, "lastlogintime");
                login = get(jsonObject, "login");
                regip = get(jsonObject, "regip");
                regdate = get(jsonObject, "regdate");
                content = get(jsonObject, "content");
                thirdtype = get(jsonObject, "thirdtype");
                thirduid = get(jsonObject, "thirduid");
                bankname = get(jsonObject, "bankname");
                bankaddress = get(jsonObject, "bankaddress");
                bankcard = get(jsonObject, "bankcard");
                c_bankname = get(jsonObject, "c_bankname");
                c_bankaddress = get(jsonObject, "c_bankaddress");
                c_bankcard = get(jsonObject, "c_bankcard");
                android_must_update = get(jsonObject, "android_must_update");
                android_last_version = get(jsonObject, "android_last_version");
                android_update_url = get(jsonObject, "android_update_url");
                servicerange = get(jsonObject, "servicerange");
                workyears = get(jsonObject, "workyears");
                if (!jsonObject.isNull("imgItems1") && !isNull(get(jsonObject, "imgItems1"))) {
                    JSONArray jsonArray = jsonObject.getJSONArray("imgItems1");
                    for (int i = 0; i < jsonArray.length(); i++) {
                        imgItems1.add(new Image(jsonArray.getJSONObject(i)));
                    }
                }
                if (!jsonObject.isNull("imgItems2") && !isNull(get(jsonObject, "imgItems2"))) {
                    JSONArray jsonArray = jsonObject.getJSONArray("imgItems2");
                    for (int i = 0; i < jsonArray.length(); i++) {
                        imgItems2.add(new Image(jsonArray.getJSONObject(i)));
                    }
                }
                if (!jsonObject.isNull("imgItems3") && !isNull(get(jsonObject, "imgItems3"))) {
                    JSONArray jsonArray = jsonObject.getJSONArray("imgItems3");
                    for (int i = 0; i < jsonArray.length(); i++) {
                        imgItems3.add(new Image(jsonArray.getJSONObject(i)));
                    }
                }
            } catch (JSONException e) {
                throw new DataParseException(e);
            }
        }
    }

    //id,username,email,password,nickname,charindex,birthday,sex,stature,weight,waistline,goalstepnum,chronicdisease,mobile,selfsign,avatar,avatarbig,backimg,district_name,province,city,district,onlineflag,validflag,vestflag,score,feeaccount,lng,lat,deviceid,devicetype,channelid,lastloginversion,lastlogintime,content,regdate,alipayname,bankname,bankuser,bankcard,age,
    public User(String id,
                String usertype,
                String serviceflag,
                String username,
                String email,
                String password,
                String paypassword,
                String cashpassword,
                String nickname,
                String charindex,
                String mobile,
                String tel,
                String avatar,
                String avatarbig,
                String district_name,
                String onlineflag,
                String validflag,
                String vestflag,
                String score,
                String feeaccount,
                String lng,
                String lat,
                String deviceid,
                String devicetype,
                String channelid,
                String lastloginversion,
                String lastlogintime,
                String login,
                String regip,
                String regdate,
                String content,
                String thirdtype,
                String thirduid,
                String bankname,
                String bankaddress,
                String bankcard,
                String c_bankname,
                String c_bankaddress,
                String c_bankcard,
                String token,
                String android_must_update,
                String android_last_version,
                String android_update_url) {
        super(token);
        this.id = id;
        this.usertype = usertype;
        this.serviceflag = serviceflag;
        this.username = username;
        this.email = email;
        this.password = password;
        this.paypassword = paypassword;
        this.cashpassword = cashpassword;
        this.nickname = nickname;
        this.charindex = charindex;
        this.mobile = mobile;
        this.avatar = avatar;
        this.avatarbig = avatarbig;
        this.district_name = district_name;
        this.onlineflag = onlineflag;
        this.validflag = validflag;
        this.vestflag = vestflag;
        this.score = score;
        this.feeaccount = feeaccount;
        this.lng = lng;
        this.lat = lat;
        this.deviceid = deviceid;
        this.devicetype = devicetype;
        this.channelid = channelid;
        this.lastloginversion = lastloginversion;
        this.lastlogintime = lastlogintime;
        this.login = login;
        this.regip = regip;
        this.regdate = regdate;
        this.content = content;
        this.thirdtype = thirdtype;
        this.thirduid = thirduid;
        this.bankname = bankname;
        this.bankaddress = bankaddress;
        this.bankcard = bankcard;
        this.c_bankname = c_bankname;
        this.c_bankaddress = c_bankaddress;
        this.c_bankcard = c_bankcard;
        this.android_must_update = android_must_update;
        this.android_last_version = android_last_version;
        this.android_update_url = android_update_url;


    }


    public void refreshUserData(User user) {
        this.id = user.id;
        this.username = user.username;
        this.email = user.email;
        this.password = user.password;
        this.nickname = user.nickname;
        this.charindex = user.charindex;
        this.mobile = user.mobile;
        this.avatar = user.avatar;
        this.avatarbig = user.avatarbig;
        this.district_name = user.district_name;
        this.onlineflag = user.onlineflag;
        this.validflag = user.validflag;
        this.vestflag = user.vestflag;
        this.score = user.score;
        this.feeaccount = user.feeaccount;
        this.lng = user.lng;
        this.lat = user.lat;
        this.deviceid = user.deviceid;
        this.devicetype = user.devicetype;
        this.channelid = user.channelid;
        this.lastloginversion = user.lastloginversion;
        this.lastlogintime = user.lastlogintime;
        this.content = user.content;
        this.regdate = user.regdate;
        this.bankname = user.bankname;
        this.bankcard = user.bankcard;
        this.bankaddress = user.bankaddress;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsertype() {
        return usertype;
    }

    public void setUsertype(String usertype) {
        this.usertype = usertype;
    }

    public String getServiceflag() {
        return serviceflag;
    }

    public void setServiceflag(String serviceflag) {
        this.serviceflag = serviceflag;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPaypassword() {
        return paypassword;
    }

    public void setPaypassword(String paypassword) {
        this.paypassword = paypassword;
    }

    public String getCashpassword() {
        return cashpassword;
    }

    public void setCashpassword(String cashpassword) {
        this.cashpassword = cashpassword;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getCharindex() {
        return charindex;
    }

    public void setCharindex(String charindex) {
        this.charindex = charindex;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getAvatarbig() {
        return avatarbig;
    }

    public void setAvatarbig(String avatarbig) {
        this.avatarbig = avatarbig;
    }

    public String getDistrict_name() {
        return district_name;
    }

    public void setDistrict_name(String district_name) {
        this.district_name = district_name;
    }

    public String getOnlineflag() {
        return onlineflag;
    }

    public void setOnlineflag(String onlineflag) {
        this.onlineflag = onlineflag;
    }

    public String getValidflag() {
        return validflag;
    }

    public void setValidflag(String validflag) {
        this.validflag = validflag;
    }

    public String getVestflag() {
        return vestflag;
    }

    public void setVestflag(String vestflag) {
        this.vestflag = vestflag;
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    public String getFeeaccount() {
        return feeaccount;
    }

    public void setFeeaccount(String feeaccount) {
        this.feeaccount = feeaccount;
    }

    public String getLng() {
        return lng;
    }

    public void setLng(String lng) {
        this.lng = lng;
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat;
    }

    public String getDeviceid() {
        return deviceid;
    }

    public void setDeviceid(String deviceid) {
        this.deviceid = deviceid;
    }

    public String getDevicetype() {
        return devicetype;
    }

    public void setDevicetype(String devicetype) {
        this.devicetype = devicetype;
    }

    public String getChannelid() {
        return channelid;
    }

    public void setChannelid(String channelid) {
        this.channelid = channelid;
    }

    public String getLastloginversion() {
        return lastloginversion;
    }

    public void setLastloginversion(String lastloginversion) {
        this.lastloginversion = lastloginversion;
    }

    public String getLastlogintime() {
        return lastlogintime;
    }

    public void setLastlogintime(String lastlogintime) {
        this.lastlogintime = lastlogintime;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getRegip() {
        return regip;
    }

    public void setRegip(String regip) {
        this.regip = regip;
    }

    public String getRegdate() {
        return regdate;
    }

    public void setRegdate(String regdate) {
        this.regdate = regdate;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getThirdtype() {
        return thirdtype;
    }

    public void setThirdtype(String thirdtype) {
        this.thirdtype = thirdtype;
    }

    public String getThirduid() {
        return thirduid;
    }

    public void setThirduid(String thirduid) {
        this.thirduid = thirduid;
    }

    public String getBankname() {
        return bankname;
    }

    public void setBankname(String bankname) {
        this.bankname = bankname;
    }

    public String getBankaddress() {
        return bankaddress;
    }

    public void setBankaddress(String bankaddress) {
        this.bankaddress = bankaddress;
    }

    public String getBankcard() {
        return bankcard;
    }

    public void setBankcard(String bankcard) {
        this.bankcard = bankcard;
    }

    public String getC_bankname() {
        return c_bankname;
    }

    public void setC_bankname(String c_bankname) {
        this.c_bankname = c_bankname;
    }

    public String getC_bankaddress() {
        return c_bankaddress;
    }

    public void setC_bankaddress(String c_bankaddress) {
        this.c_bankaddress = c_bankaddress;
    }

    public String getC_bankcard() {
        return c_bankcard;
    }

    public void setC_bankcard(String c_bankcard) {
        this.c_bankcard = c_bankcard;
    }

    @Override
    public String getAndroid_must_update() {
        return android_must_update;
    }

    public void setAndroid_must_update(String android_must_update) {
        this.android_must_update = android_must_update;
    }

    @Override
    public String getAndroid_last_version() {
        return android_last_version;
    }

    public void setAndroid_last_version(String android_last_version) {
        this.android_last_version = android_last_version;
    }

    @Override
    public String getAndroid_update_url() {
        return android_update_url;
    }

    public void setAndroid_update_url(String android_update_url) {
        this.android_update_url = android_update_url;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public ArrayList<Image> getImgItems1() {
        return imgItems1;
    }

    public void setImgItems1(ArrayList<Image> imgItems1) {
        this.imgItems1 = imgItems1;
    }

    public ArrayList<Image> getImgItems2() {
        return imgItems2;
    }

    public void setImgItems2(ArrayList<Image> imgItems2) {
        this.imgItems2 = imgItems2;
    }

    public ArrayList<Image> getImgItems3() {
        return imgItems3;
    }

    public void setImgItems3(ArrayList<Image> imgItems3) {
        this.imgItems3 = imgItems3;
    }

    public String getServicerange() {
        return servicerange;
    }

    public void setServicerange(String servicerange) {
        this.servicerange = servicerange;
    }

    public String getWorkyears() {
        return workyears;
    }

    public void setWorkyears(String workyears) {
        this.workyears = workyears;
    }
}
